package com.atguigu.crowd.util;

/**
 * @author zzqstart
 * @Description
 * @date 2022-08-29 0:29
 */
public class ResultEntity<T> {
    
    public static final String SUCCESS="SUCCESS";
    public static final String FALIED="FALIED";
    
    //用来封装当前请求处理的结果是成功还是失败
    private String result;
    //请求处理失败时返回的错误信息
    private String message;
    //要返回的数据
    private T data;
    
    /**
     * @Description 请求处理成功且不需要返回数据时的工具方法
     * 
     * @Author zzqstart
     * @Date 2022/8/29 0:36
     * @Param []
     * @return com.atguigu.crowd.util.ResultEntity<E>
     **/
    public static <E> ResultEntity<E> successWithoutData(){
        return new ResultEntity<E>(SUCCESS,null,null);
    }
    
    /**
     * @Description 请求处理成功且需要返回数据时使用的工具方法
     * 
     * @Author zzqstart
     * @Date 2022/8/29 0:41
     * @Param [data]
     * @return com.atguigu.crowd.util.ResultEntity<E>
     **/
    public static <E> ResultEntity<E> successWithData(E data){
        return new ResultEntity<E>(SUCCESS,null,data);
    }
    
    /**
     * @Description 请求处理失败后使用的错误信息
     * 
     * @Author zzqstart
     * @Date 2022/8/29 1:11
     * @Param [message]
     * @return com.atguigu.crowd.util.ResultEntity<E>
     **/
    public static <E> ResultEntity<E> failed(String message){
        return new ResultEntity<E>(FALIED,message,null);
    }

    public ResultEntity() {
    }

    public ResultEntity(String result, String message, T data) {
        this.result = result;
        this.message = message;
        this.data = data;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResultEntity{" +
                "result='" + result + '\'' +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
